package file.fileread;


import java.io.*;
import java.sql.SQLException;
import java.util.logging.*;


/**
 *
 * @author javadb.com
 */
public class Readindexstock  {
String symbolx;int Block[]=new int[12];
public static String[]sym=new String[9];String x ="";
public static int status=1;
                   
    /**
     * Reads text from a file line by line
     */
    public void readFromFile(String textString,String SET) throws SQLException {

        
        BufferedReader bufferedReader = null;
        String xc ="";
        String ya;
        PrintStream out;
      // System.out.println(textString);
        
        try {
            //Construct the BufferedReader object
            bufferedReader = new BufferedReader(new StringReader(textString));
            String line = null;
          
            while ((line = bufferedReader.readLine()) != null) {
                  int count1 = 0;int b[] = new int[1000];int c[] =new int[1000];int count2 = 0;
                //System.out.println(line.toString());
                            String linenumber = "";
                            String y ="";
                            
                        
                         //-->1    datetime:
                            
                    if(line.contains("<a href=\"/C13_MarketSummary.jsp?detail="+SET+"\" class=\"greenlink\" target=\"_top\">")){
                            for(int i=0;i<5;i++){
                                char xx=line.charAt(i);
                                
                                if(xx>='0'&&xx<='9'){
                                    linenumber+=line.substring(i, i+1);       
                                }        
                            } //System.out.print(linenumber);  //System.out.println(aa);
                       if(line.startsWith(linenumber)){
                        for(int i=0;i<line.length();i++){
                       char a= line.charAt(i);
                      if(a=='>'){
                          ++count1;
                         b[count1]=i;
                      }else if(a=='<'){
                           ++count2;
                          c[count2]=i;
                      }}
                   for(int i=0;i<100;i++){
                          if(b[i]!=0&&c[i]!=0){
                            // if(isDigit(line.substring(b[i]+1,c[i]))){
                                 ya=line.substring(b[i]+1,c[i]);
                                 if(ya.equals(SET)){
                                     sym[0]=ya;
                                     
                               //  }
                             }
                        } }
                  //  x+="@"+y;
                    

                    for(int k=1;k<=8;k++){
                        Block[k]=Integer.parseInt(linenumber)+k;
                        
                        
                        
                    }
                     }
                    // System.out.println(Block[1]);
                   
                            ////////////////////////////////////
                    // System.out.print(""+y);
                     } 
                        for(int k=1;k<=8;k++){
                       
                        if(line.startsWith(String.valueOf(Block[k])+"-->")){
                        for(int i=0;i<line.length();i++){
                       char a= line.charAt(i);
                      if(a=='>'){
                          ++count1;
                         b[count1]=i;
                      }else if(a=='<'){
                           ++count2;
                          c[count2]=i;
                      }}
                   for(int i=0;i<100;i++){
                          if(b[i]!=0&&c[i]!=0){
                            // if(isDigit(line.substring(b[i]+1,c[i]))){              
                                      xc=line.substring(b[i]+1,c[i]);
                                       y=xc;
                             }//}
                             }

                      
                          
                       
                          
                           
                       
                        
                    //x+="@"+y;
                  sym[k]=y;
                   if(k==8){
                    break;
                   
                    

                           }
                     //  System.out.print(y);
                     }
                        
                   
                    }
                 
 
        
           
         if(line.contains("<div class=\"fr \" style=\"width:50px; text-align:right;\">Close</div>")){
             // status="<html><font color=red>Close</font></html>";
             status=0;
         }else if(line.contains("<div class=\"fr \" style=\"width:50px; text-align:right;\">Open</div>")){
               //status="<html><font color=greed>Open</font></html>";
             status=1;
         }else if(line.contains("<div class=\"fr \" style=\"width:50px; text-align:right;\">Intermission</div>")){
             status=2;
         }else if(line.contains("<div class=\"fr \" style=\"width:50px; text-align:right;\">Call</div>")){
             status=3;
         }else if(line.contains("<div class=\"fr \" style=\"width:50px; text-align:right;\">Run-off</div>")){
             status=4;
         }
         
         
         
            }
        }
 catch (FileNotFoundException ex) {
            Logger.getLogger(Readindexstock.class.getName()).log(Level.SEVERE, null, ex);
        }         catch (IOException ex) {
            ex.printStackTrace();
        } finally {
            //Close the BufferedReader
            try {
                if (bufferedReader != null)
                    bufferedReader.close();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws SQLException {
        new Readindexstock().readFromFile("SETINDEXFile.txt","");
        
    // for(int l=0;l<sym.length;l++){
            
    //        System.out.print(sym[l]+"@");
   //   }
      
    }
    
     public static boolean isDigit(String s)   {
     boolean right = false;
      char c = 0;
      for (int index = 0; index < s.length(); index ++)  {
            c = s.charAt(index);
            if (c >= '0' || c <= '9'||c=='.')  {
            right = true;
           }
       }
      return right;
}
        
}

